package com.example.administrator.yuejian35.Recommend.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.administrator.yuejian35.R;
import com.example.administrator.yuejian35.Recommend.activity.ApplyInfoActivity;
import com.example.administrator.yuejian35.Recommend.bean.ShowApplyresult;
import com.example.administrator.yuejian35.Recommend.fragment.viewholder.ApplyItemViewHolder;
import com.squareup.picasso.Picasso;

import java.util.ArrayList;
import java.util.List;

import static com.example.administrator.yuejian35.Config.Img_URL;

/**
 * Created by HP on 2017/9/26.
 */

public class ApplyListAdapter extends RecyclerView.Adapter {
    private Context context;
    private List<ShowApplyresult> clubList=new ArrayList<>();

    public ApplyListAdapter(Context c, List<ShowApplyresult> clubList){
        this.context = c;
        this.clubList.addAll(clubList);
    }


    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        //1)  将item.xml 生成 itemView  -  View
        //2)  生成MyViewHolderd对象
        View itemView = LayoutInflater.from(context).inflate(R.layout.item_apply,parent,false);
        ApplyItemViewHolder holder = new ApplyItemViewHolder(itemView);
        return holder;
    }



    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
        //用于绑定数据
        //转换类型
        ApplyItemViewHolder clubItemViewHolder= (ApplyItemViewHolder) holder;

        clubItemViewHolder.apply_id.setText("订单编号：2300415"+clubList.get(position).getCourseapplyid());
        clubItemViewHolder.course_name.setText(clubList.get(position).getCoursename());
        clubItemViewHolder.course_price.setText(clubList.get(position).getPrice()+"元/人");
        clubItemViewHolder.num.setText("购买"+clubList.get(position).getNum()+"份");
        clubItemViewHolder.apply_time.setText("下单时间："+clubList.get(position).getApplytime());
        int p= Integer.parseInt(clubList.get(position).getPrice());
        int n= Integer.parseInt(clubList.get(position).getNum());
       final int all=p*n;
        clubItemViewHolder.sum.setText("订单总额："+all+"元");
        if(clubList.get(position).getApplytime().equals("1"))
        {
            clubItemViewHolder.apply_state.setText("已参加");
        }
        else{
            clubItemViewHolder.apply_state.setText("未参加");
        }

        clubItemViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(context,ApplyInfoActivity.class);
                intent.putExtra("applyid",clubList.get(position).getCourseapplyid());
                intent.putExtra("sum",all);
                context.startActivity(intent);
            }
        });
        Picasso.with(context)
                .load(Img_URL+clubList.get(position).getCoursepic())
                .into(clubItemViewHolder.course_pic);

    }

    @Override
    public int getItemCount() {
        return clubList.size();
    }
}

